/**
  ******************************************************************************
  * @file    Hourmeter.h
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   This file contains headers for Hourmeter function
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */

#ifndef __HOURMETER_H_
#define __HOURMETER_H_
#include "stm32f10x.h"
#define HRM_PRESC_MAX 				720         //0.1h=6 min=6x60 sec=360 sec.. Multiply with task freq @500ms =>2/sec; 
#define HRM_MAX 					999999

#define ODOMETER_PRESC_THRS		    3600        //speed = [0.1km/h]=[0.1km/3600s] = [0.1km/(3600*100msec)]; 100ms=task interval @ 0.1km increment
#define ODOMETER_MAX_KM			    999999

#define	DIVIDE_A_MILE	            0.621371

#define CHANGE_ENG_OIL              BIT0
#define CHANGE_AIR_FILTER           BIT1
#define SERVICE_ENG                 BIT2
#define SERVICE_MACHINE             BIT3

#define BK_Add1                     4
#define BK_Add2                     6
#define BK_Add3                     8
#define BK_Add4                     10
#define BK_Add5                     12
#define BK_Add6                     14
#define BK_Add7                     16
#define BK_Add8                     18

#define HM1_BK_ADRESS               BK_Add1
#define HM2_BK_ADRESS               BK_Add2
#define HM3_BK_ADRESS               BK_Add3
#define HM4_BK_ADRESS               BK_Add4
typedef struct
{
	u32	HM1_value;	 // key on hours
	u32	HM2_value;	 // lift hours
	u32	HM3_value;   // track hours
    u32	HM4_value;   // steer used

	u32	Pre_HM1_value;	
	u32	Pre_HM2_value;	
	u32	Pre_HM3_value;	
    u32	Pre_HM4_value;	
    
	s16 Service_hours1;
	s16 Service_hours2;
	s16 Service_hours3;
    s16 Service_hours4;

	s16 Pre_service_hours1;
	s16 Pre_service_hours2;
	s16 Pre_service_hours3;
    s16 Pre_service_hours4;

	s16 Service_days1;
	s16 Service_days2;
	s16 Service_days3;
    s16 Service_days4;

	s16 Pre_service_days1;
	s16 Pre_service_days2;
	s16 Pre_service_days3;
    s16 Pre_service_days4;

	u16 HM1_prescaler;         //hourmeter prescaler 
	u16 HM2_prescaler;     
	u16 HM3_prescaler;     
    u16 HM4_prescaler;  
	  
	s16 prescaler1;
	s16 prescaler2;     
	s16 prescaler3;
	s16 prescaler4;   
    s16 month;
    s16 day;
}HourMtr_TypeDef;

struct ClearScreenFlag
{
    int ClearHrmOnce:1;
    int ClearMM1Once:1;
    int ClearMM2Once:1;
    int ClearMM3Once:1;
    int ClearAdvOnce:1;
    int ClearMCOnce:1;
};

union CLEAR_SCREEN_FLAGS
{
    s16                     all;
    struct ClearScreenFlag  bit;
};
#define ClearHrmOnce                     ClearScreenFlags.bit.ClearHrmOnce
#define ClearMM1Once                     ClearScreenFlags.bit.ClearMM1Once
#define ClearMM2Once                     ClearScreenFlags.bit.ClearMM2Once
#define ClearMM3Once                     ClearScreenFlags.bit.ClearMM3Once
#define ClearAdvOnce                     ClearScreenFlags.bit.ClearAdvOnce 
#define ClearMCOnce                      ClearScreenFlags.bit.ClearMCOnce

extern HourMtr_TypeDef          Hrm_Struct; 
extern union CLEAR_SCREEN_FLAGS ClearScreenFlags;

extern u8 WriteBackupRegister(u16 BK_Address, u32 Data);
extern u32 ReadBackupRegister(u16 BK_Address);
extern void check_matin_hour(void);
extern u8 PreMatinFlag;
extern u8 MatinInfoScreen;
/* Exported functions --------------------------------------------------------*/ 
#endif


